<template>
  <div style="height: 100%;overflow: auto">
    <popup :value="true" :should-rerender-on-show="true" :popup-style="{'z-index':500}"
        :show-mask="false" height="100%" :hide-on-blur="false">
      <x-header v-bind:left-options="{backText: '', preventGoBack: 'true'}" @on-click-back="$router.go(-1)">{{configs.formName}}</x-header>
      <div style="height: height">
        <tab :line-width="3" custom-bar-width="18px" active-color="#343434" default-color="#545454" bar-active-color="#F1A201" v-model="tab" v-if="sign">
          <tab-item v-for="(item, index) in tab_titles" :key="index" :selected="tab === index"
            @click="tab = index">{{item}}</tab-item>
        </tab>
        <!-- 详情 -->
        <div v-if="tab == 0" class="content-container">
          <template v-for="(item, index) in list" 
              v-if="!item.prop||(item.prop&&!item.prop.showMode)||(item.prop&&item.prop.showMode == 'show')
              ||(item.prop.showMode == 'showOnTaskNode'&&item.prop.showNodes.includes(row.NODEID))">
            <!-- userchoose -->
            <group label-width="100px" :gutter="-1" :key="index" v-if="item.type == 'userchoose'">
              <person-tree :ref="item.Id"  v-model="item.value" :title="item.text" value-align="left" :multiple="item.prop.chooseType == 'multi'" :readonly="row.STATE != '待验收'"></person-tree>
            </group>
            <!-- radio -->
            <group label-width="100px" :gutter="-1" :key="index" v-else-if="item.type == 'radio'">
              <!-- <x-switch :value="false" :title="item.text" v-model="item.value" :disabled="!flowConfig[item.Id]||(flowConfig&&flowConfig[item.Id]&&!flowConfig[item.Id].editable)"></x-switch> -->
              <popup-radio  v-model="item.value" :title="item.text" :placeholder="map[item.type].ph" value-align="right" :options="radio(item.prop.items)" :readonly="!flowConfig[item.Id]||(flowConfig&&flowConfig[item.Id]&&!flowConfig[item.Id].editable)" @on-hide="closeMask"></popup-radio>
            </group>
            <!-- userchoose -->
            <group label-width="100px" :gutter="-1" :key="index" v-else-if="item.type == 'select'" >
              <popup-picker  v-model="item.value" :title="item.text"  :data="analyze(item.prop.items)" 
                  :readonly="!flowConfig[item.Id]||(flowConfig&&flowConfig[item.Id]&&!flowConfig[item.Id].editable)" @on-hide="closeMask"></popup-picker>
            </group>
            <!-- input/textarea -->
            <group label-width="100px" :gutter="-1" :key="index" v-else-if="item.type!='attachment' && item.type!='detailtable'" class="detail">
              <!-- v-if不可编辑 -->
              <cell :title="item.text" value-align="right" v-if="item.type!='text' || row.STATE != '待验收'">
                <div class="black">{{item.value}}</div>
              </cell>
              <!-- 可编辑 -->
              <component :is="map[item.type].comp" :placeholder="map[item.type].ph" columns="1" :title="item.text" v-model="item.value" :rows="1" autosize v-else></component> 
            </group>
            <group label-width="100px" :gutter="-1" :key="index" v-else-if="item.type!='attachment' && item.type!='detailtable'" class="detail">
              <!-- v-if不可编辑 -->
              <cell :title="item.text" value-align="right" v-if="!flowConfig[item.Id]||(flowConfig&&flowConfig[item.Id]&&!flowConfig[item.Id].editable)">
                <div class="black">{{item.value}}</div>
              </cell>
              <!-- 可编辑 -->
              <component :is="map[item.type].comp" :placeholder="map[item.type].ph" columns="1" :title="item.text" v-model="item.value" :rows="1" autosize v-else></component> 
            </group>
            <!-- userchoose -->
            <group v-else label-width="100px" :key="index" :title="item.text" style="margin-bottom:10px">
              <picture-upload v-if="item.type == 'attachment'" v-model="item.value" :pageToken="pageToken" 
                :fieldToken="fieldToken" :readonly="row.STATE != '待验收'"></picture-upload>
                <detail-table v-if="item.type == 'detailtable'" :prop="item.prop"  :value="item.value" :title="item.text"></detail-table> 
            </group>
          </template>
          <div  v-if="showButton" class="entrust-btn" @click="confirmDlg()">验收</div>
        </div>
        <!-- 流程 -->
        <div v-if="tab == 1" class="content-container">
          <timeline timeline-theme="#E8EAEB">
            <template v-for="(item, index) in flowList">
              <timeline-item :hollow="true" :key="index" line-color="red">
                <div class="flow-box">
                  <div class="flow-box-time">
                    <div>{{item.endTime.split(" ")[0]}}</div>
                    <div>{{item.endTime.split(" ")[1]}}</div>
                  </div>
                  <div class="flow-box-title">{{item.nodeName}}</div>
                  <div class="flow-box-state"><span>{{item.commandMessage?item.commandMessage:'待办'}}</span></div>
                  <div class="flow-box-line"></div>
                  <div class="flow-box-content">
                    <div class="flow-box-point"></div>
                    <span>处理人</span>&nbsp;&nbsp;
                    <div class="name">{{item.assignessName}}</div>
                  </div>
                  <div class="flow-box-content">
                    <div class="flow-box-point"></div>
                    <span>审批意见</span>&nbsp;&nbsp;
                    <!-- v-html="item.taskComment" -->
                    <span v-html="item.taskComment"></span>
                  </div>
                </div>
              </timeline-item>
            </template>
          </timeline>
        </div>
      </div>
    </popup>
  </div>
</template>

<script>
  import {
    Timeline,
    TimelineItem,
    TimelineTitle
  } from 'vue-cute-timeline'
  export default {
      name: "qualityInfo",
    mounted(){
      this.getData1();
      this.getData();
      this.pageToken = this.guid();
      this.fieldToken = this.guid();
    },
    data(){
        return{
          nameInfo: [],
          tab: 0,
          tab_titles: ['详情', '流转'],
          sign: true,
          showButton: false,
          formData: [],//原始的业务数据
          buttonList: [],//审批按钮
          flowList: [],//流程列表
          list: [],//业务数据
          advice: '',//审批意见
          newName: '',//委托人
          newDept: '',
          reason: '',//委托原因
          pageToken: "",
          fieldToken: "",
          buttonId: '',
          accordionList : [{'name':'a'},{'name':'b'},{'name':'c'}],
          map: {
            'input': {
              comp: 'x-input',
              ph: '请输入'
            },
            'datetime': {
              comp: 'datetime',
              ph: '请选择'
            },
            'select': {
              comp: 'popup-picker',
              ph: '请选择'
            },
            'userchoose': {
              comp: 'person-tree',
              ph: '请选择'
            },
            'detailtable': {
              comp: 'detail-table'
            },
            'text': {
              comp: 'x-textarea',
              ph: '请输入'
            },
            'attachment': {
              comp: 'photo-upload'
            },
            'radio': {
              comp: 'popup-radio',
              ph: '请选择'
            }
          },//对应组件
        }
    },
    methods:{
      setTabbar() {
        let state = this.$router.currentRoute.query.state;
        if(state == "未验收" || state == "待验收"){
          this.sign = false
        } else {
          this.sign = true
        }
        if(state == "待验收"){
          this.showButton = true
        }
      },
      getQuaParams(data){
        let configs = JSON.parse(data.DATACONFIGS);
        let formId_Detail = configs.detailObjIds; //明细表业务对象
        let vDetail = "";
        if (formId_Detail == "") {
          vDetail = "";
        } else {
          vDetail = "," + formId_Detail;
        }
        let params = {
          _method: "formService.getFormData",
          requestEventData: {
            eventType: "formInitEvent",
            formType: 1,
            bizObjId: configs.bizObjId,
            formId: configs.formId
          },
          useType: "view",
          getData: {
            useType: "view",
            objName: configs.bizObjId,
            relatedObj: [configs.bizObjId, vDetail],
            pk: [{
              key: "GUID",
              value: data.GUID
            }]
          },
          getSysVar: data.items,
          getToolbar: {
            useType: "modify",
            objName: configs.bizObjId,
            viewId: configs.formId
          },
          getFormVerify: {
            objName: configs.bizObjId,
            viewId: configs.formId
          },
        };
       
        // if(configs.bizObjId == 'SZJC_FENBUPROQUALITYCHECK'){
          params['getSysVar'] = {
            PRJNAME: "{sysLoginUser.projectName}",
            INPUTERFULLNAME: "{sysLoginUser.userName}",
            INPUTNAME: "{sysLoginUser.loginId}",
            PHONENUM: "{sysLoginUser.tel}",
            INPUTERDEPTNAME: "{sysLoginUser.orgName}",
            INPUTERDEPTID: "{sysLoginUser.orgId}",
            INPUTERDEPTPATHID: "{sysLoginUser.orgPathId}",
            INPUTDATE: "{sysDate.Today}"
          }
        // }
        return  params = JSON.stringify(params)
      },

      getData1() {
        let nameInfo = [];
        let configs = JSON.parse(this.row.DATACONFIGS);
        this.$ajax({
          method: 'post',
          url: '/sxdtpm/servlet/Action.cmd?_isBreak=false&objName='+configs.bizObjId+'&_useType=modify&_pk=GUID&_pkValue=' +this.row.GUID,
          data : {
            FixJSON: '{"_method":"'+ configs.bizObjId + (configs.bizObjId=="SZJC_FENBUPROQUALITYCHECK" ? '.getmessage"' : '.getMessage"') + ',"GUID":"'+this.row.GUID+'"}'
          }
        }).then((res) => {
          this.nameInfo = res.data.out0
        })
      },
      getData() {
        let configs = JSON.parse(this.row.DATACONFIGS);
        let params = this.getQuaParams(this.row) || '';
        
        //获取业务数据（主表、明细表（如果有））及任务处理的按钮信息
        this.$ajax({
          method: 'post',
          url: this.COMMON_URL+'?_isBreak=false&objName='+configs.bizObjId+'&_useType=modify&_pk=GUID&_pkValue=' +this.row.GUID,
          data : {
            FixJSON: params
          }
        }).then((res) => {
          //业务数据
          this.buttonId = res.data.getToolbar[0][0].id || '';
          if (res.data.getData) {
            this.formData = res.data.getData;
            //_isBreak=false&objName=&_useType=view&_pk=GUID&_pkValue=129d427ba3d42403fc14d6db233987d1&_treeNodeId=&_treeNodeName=undefined
            let value = res.data.getData[configs.bizObjId][0];
            let value1 = res.data.getSysVar;
           
            this.list = configs.items.map(item => {
              item.value = value[item.Id] && value[item.Id].val ? (value[item.Id].dis || value[item.Id].val) :
                item.type == "select" || item.type == "detailtable" ? [] : "";
              if(item.type == "detailtable"){
                let detailMethod = '';
                if(configs.bizObjId == "SZJC_FXPROQUALITYCHECK"){
                  detailMethod = '.getJypData'
                } else if(configs.bizObjId == "SZJC_FENBUPROQUALITYCHECK"){
                  detailMethod = '.getFxData'
                } else if(configs.bizObjId == "SZJC_DANWEIPROQUALITYCHECK"){
                  detailMethod = '.getFbData'
                }
                // item.value = res.data.getData[item.Id]
                this.$ajax({
                  method: 'post',
                  // url: '/sxdtpm/servlet/Action.cmd',
                    url:this.COMMON_URL,
                  data : {
                    FixJSON: '{"_method":"' + configs.bizObjId + detailMethod + '","GUID":"' + value.GUID.val + '"}'
                  }
                }).then((res1) => {
                  item.value = new Array();
                  item.value = res1.data.dataVal || res1.data.data;
                })
              }
              return item
            });
            this.list.map((it) => {
              if(value1[it.Id] && it.value == ''){
                it.value = value1[it.Id]
              }
            });
            this.list.filter((it) => {
              if(it.Id == 'INPUTDATE') {
                it.value = this.formatDateTime(value1[it.Id])
              }
            });
            this.list.map((it) => {
              if(it.Id == 'INPUTERNAME' && configs.bizObjId == "SXDT_JYPYS_DETAIL") {
                it.value = value1['INPUTNAME']
              }
            });
              
            let nameInfo = this.nameInfo;
            if (nameInfo.length > 0){
              this.list.map(it => {
                if(configs.bizObjId=="SXDT_JYPYS_DETAIL" || configs.bizObjId=="SZJC_FXPROQUALITYCHECK"){
                  if(it.Id == 'UNITNAME'){
                    it.value = configs.bizObjId=="SXDT_JYPYS_DETAIL" ? nameInfo[2].PARENTNAME : nameInfo[2].NAME
                  }
                  if(it.Id == 'UNITID'){
                    it.value = nameInfo[2].ID
                  }
                  if(it.Id == 'BRANCHNAME'){
                    it.value = nameInfo[1].NAME
                  }
                  if(it.Id == 'BRANCHID'){
                    it.value = nameInfo[1].ID
                  }
                  if(it.Id == 'SUBITEMNAME'){
                    it.value = nameInfo[0].NAME
                  }
                  if(it.Id == 'SUBITEMID'){
                    it.value = nameInfo[0].ID
                  }
                }
                if(configs.bizObjId=="SZJC_FENBUPROQUALITYCHECK"){
                  if(it.Id == 'UNITNAME'){
                    it.value = nameInfo[1].PARENTNAME
                  }
                  if(it.Id == 'UNITID'){
                    it.value = nameInfo[1].ID
                  }
                  if(it.Id == 'BRANCHNAME'){
                    it.value = nameInfo[0].NAME
                  }
                  if(it.Id == 'BRANCHID'){
                    it.value = nameInfo[0].ID
                  }
                }
                if(configs.bizObjId=="SZJC_DANWEIPROQUALITYCHECK"){
                  if(it.Id == 'UNITNAME'){
                    it.value = nameInfo[1].PARENTNAME
                  }
                  if(it.Id == 'UNITID'){
                    it.value = nameInfo[1].ID
                  }
                }
              })
            }
            
           console.log(this.list)
            // this.$store.commit('updateLoadingStatus', false);
            this.getApprovalList();
            this.setTabbar()
          }
          //操作按钮
          if (res.data.getToolbar) {
            this.buttonList = res.data.getToolbar[0]
          }
        }).catch((err)=>{
          console.log(err);
        });
        
      },
      //获取流程意见
      getApprovalList() {//TODO 待完成
        
        let configs = JSON.parse(this.row.DATACONFIGS);
        let GUID = this.row.GUID;
        let objName = configs.bizObjId;
        let vText = '{"_method":"flow.getInstIdByBizKey","_param":["' + GUID + '"]}';

         this.$ajax({
          method: 'post',
          url: this.COMMON_URL+'?_isBreak=false&objName='+ objName +'&_useType=view&_pk=GUID&_pkValue='+ GUID,
          data: {
            FixJSON: vText
          }
        }).then((res) => {
          if(res && res.data && res.data.instId){
            let instId = res.data.instId;
            let vText1 =  '{"_method":"flow.getTaskProcess","_param":["' + instId + '"]}';
            this.$ajax({
              method: 'post',
              url: this.COMMON_URL+'?_isBreak=false&objName=' + objName + '&_useType=view&_pk=GUID&_pkValue=' + GUID,
              data: {
                FixJSON: vText1
              }
            }).then((res) => {
              this.flowList = [];
              if (res.data && res.data.taskListEnd) {
                res.data.taskListEnd.forEach(element => {
                  let item = element;
                  item.done = true;
                  this.flowList.push(item);
                });
              }
              if (res.data && res.data.taskListIng) {
                res.data.taskListIng.forEach(element => {
                  let item = element;
                  item.done = false;
                  this.flowList.push(item)
                });
              }
              this.flowList.splice(0, 1);
            })
          }
        })

        
      },
      confirmDlg() {
        // let txt = obj.text == "拒绝" ? "退回" : obj.text;
        const _this = this // 需要注意 onCancel 和 onConfirm 的 this 指向
        this.$vux.confirm.show({
          // 组件除show外的属性
          title: "提示",
          content: "是否要执行验收操作？",
          onCancel() {},
          onConfirm() {
            _this.flowHandle();
          }
        })
      },
      //流程的提交
      flowHandle(obj) {
        
        
        let taskInfor = this.row;
        let configs = JSON.parse(taskInfor.DATACONFIGS);
        let workItemId = taskInfor.TASKID;
        let keyid = taskInfor.BIZKEY;
        let defKey = taskInfor.DEFKEY;
        let FlowID = taskInfor.INSTID;
        let nodeId = taskInfor.NODEID;
        let defId = taskInfor.DEFID;

        let formId = configs.formId; //表单id
        let bizObjId = configs.bizObjId; //业务对象
        let formId_Detail = configs.detailObjIds; //明细表业务对象

        // let saveXmlData = this.setModifyData(); //需保存的数据

        let fixJson = {};
        fixJson['_method'] = "formService.saveFormData";
        fixJson['_OBJ_NAME_'] = configs.bizObjId;
        fixJson['_FORM_ID_'] = configs.formId;
        fixJson['useType'] = "modify";
        fixJson['_ATTACHMENT_DELETE_IDS_'] = "";
        fixJson['pageToken'] = '627ceaa0-f1e2-0d5f-5f41-72e301de0c11';
        fixJson['requestEventData'] = {
          eventType: "formSubmitEvent",
          formType: 1,
          bizObjId:configs.bizObjId ,
          formId: configs.formId,
          buttonId: this.buttonId
        },
        fixJson['formData'] = {
          objName: configs.bizObjId,
          pks: ["GUID"],
          data: [{
            children: configs.bizObjId == 'SXDT_JYPYS_DETAIL' ? [] : [{objName: configs.detailObjIds, pks: ["GUID"], data: []}],
            rowData: this.setDataInfo().rowData
          }]
        };
        fixJson['formInfo'] = this.setDataInfo().formInfo;
        let vText = JSON.stringify(fixJson);
   
        this.$ajax({
          method: 'post',
          url: this.COMMON_URL+'?_objName=' + configs.bizObjId + '&_useType=modify&_pk=GUID&_pkValue=' + taskInfor.GUID,
          data: {
            FixJSON: vText
          }
        }).then((res) => {
            // this.$vux.loading.hide()
            if(this.isEmptyObject(res.data)){
              this.$store.commit("needRefreshStatus",true)
              this.$vux.toast.text('提交成功', 'middle');
              setTimeout(()=>{
                this.$vux.toast.hide();
                this.$router.go(-1);
              },1000)
            }
        }).catch((err)=>{
            console.log(err);
            alert(err);
        });
      },
      

      setDataInfo(){
        let dataInfo = {};
        let rowData = [];
        let configs = JSON.parse(this.row.DATACONFIGS);
        let formInfo = {};
        let list1 = this.list;
        let index = -1;
        list1.map((ele, i) => {
          if(ele.type == "detailtable"){
            index = i
          }
        });
        if(index > -1){
          list1.splice(index, 1);
        }
        list1.map(item => {
          let obj = {};
          let type = 'String'
          if(item.Id == 'INPUTDATE') {
            type = "TimeStamp"
          } else if(item.Id =="ATTACHMENTS" || item.Id =="ATTACHMENTS4") {
            type = "Store.ecidiDoc"
          }
          obj = {
            DataTarget: item.Id,
            Value: item.value,
            OriginalValue: item.value,
            PK: item.Id == 'GUID' ? true : false,
            DataType: type            
          }
          rowData.push(obj)
        });
        
        // if(configs.bizObjId == "SXDT_JYPYS_DETAIL" || configs.bizObjId == "SZJC_FXPROQUALITYCHECK"){
        //   rowData.push({DataTarget: "AUDITUSERFULLNAME", DataType: "String", OriginalValue: "", Value:"陈敏", PK: false});
        //   rowData.push({DataTarget: "AUDITUSERNAME", DataType: "String", OriginalValue: "", Value:"chen_m2", PK: false});
        //   rowData.push({DataTarget: "SUPUNITNAME", DataType: "String", OriginalValue: "", Value:"BIM咨询.华东勘测设计研究院有限公司", PK: false});
        //   rowData.push({DataTarget: "SUPUNITID", DataType: "String", OriginalValue: "", Value:"2798", PK: false});
        // } else if(configs.bizObjId == "SZJC_FENBUPROQUALITYCHECK"){
        //   rowData.push({DataTarget: "QUALITUUSERNAME", DataType: "String", OriginalValue: "", Value:"陈敏", PK: false});
        //   rowData.push({DataTarget: "QUALITYUSERID", DataType: "String", OriginalValue: "", Value:"chen_m2", PK: false});
        //   rowData.push({DataTarget: "CONSTRUCTIONNAME", DataType: "String", OriginalValue: "", Value:"BIM咨询.华东勘测设计研究院有限公司", PK: false});
        //   rowData.push({DataTarget: "CONSTRUCTIONID", DataType: "String", OriginalValue: "", Vvalue:"2798", PK: false});
        // } else if(configs.bizObjId == "SZJC_FENBUPROQUALITYCHECK" || configs.bizObjId == "SZJC_DANWEIPROQUALITYCHECK"){
        //   rowData.push({DataTarget: "AUDITUSERFULLNAME2", DataType: "String", OriginalValue: "", Value:"陈敏", PK: false});
        //   rowData.push({DataTarget: "AUDITUSERNAME2", DataType: "String", OriginalValue: "", Value:"chen_m2", PK: false});
        //   rowData.push({DataTarget: "AUDITDEPTFULLNAME2", DataType: "String", OriginalValue: "", Value:"BIM咨询.华东勘测设计研究院有限公司", PK: false});
        //   rowData.push({DataTarget: "AUDITDEPTNAME2", DataType: "String", OriginalValue: "", Value:"2798", PK: false});
        // };
        // rowData.push({DataTarget: "COMMENT", DataType: "String", OriginalValue: '', Value: this.advice, PK: false});
        rowData.map((it, i) => {
          formInfo[it.DataTarget] = it.Value
        });
        dataInfo = {
          rowData,
          formInfo
        }
        return dataInfo
      },

      //设置要提交的数据
      setModifyData() {
        function getCtlVal(id){
          return this.dataMap[id].value
        }
        let formData = this.formData
        let taskInfor = this.row;
        let configs = JSON.parse(taskInfor.DATACONFIGS);
        let nodeId = taskInfor.NODEID; //流程当前步奏
        let flowConfig = configs.flowConfig;
        let str = "";
        if (this.isEmptyObject(flowConfig)) {
          return "";
        }
        if (typeof (flowConfig[nodeId]) != "undefined") {
          let saveData = [];
          for (let i = 0; i < flowConfig[nodeId].items.length; i++) {
            let data = {};
            let item = flowConfig[nodeId].items[i];
            let obj = this.dataMap[item.Id];
            if (item.submit) {
              data.DataTarget = item.Id;
              data.OriginalValue = "";
              data.PK = false;
              data.DataType = "String";
              let val = "";
              val = obj.value;
              data.Value = val;
              saveData.push(data);
              if (obj.type == "userchoose") {
                data = {};
                //如果关联的UserName不为空，需要提交这部分的数据
                if (typeof (obj.prop.UserNameRelateId) != "undefined") {
                  if (obj.prop.UserNameRelateId != "") {
                    data.DataTarget = obj.prop.UserNameRelateId;
                    data.OriginalValue = "";
                    data.PK = false;
                    data.DataType = "String";
                    let val = "";
                    val = this.getUserVal(item.Id, "username");
                    data.Value = val;
                    saveData.push(data);
                  }
                }
                //如果关联的UserNo不为空，需要提交这部分的数据
                if (typeof (obj.prop.UserNoRelateId) != "undefined") {
                  if (obj.prop.UserNoRelateId != "") {
                    data.DataTarget = obj.prop.UserNoRelateId;
                    data.OriginalValue = "";
                    data.PK = false;
                    data.DataType = "String";
                    let val = "";
                    val = this.getUserVal(item.Id, "userno");
                    data.Value = val;
                    saveData.push(data);
                  }
                }
              }
            }
          }
          //执行自定义代码            
          if (typeof (configs.setModifyData) != "undefined" && configs.setModifyData != "") {
            eval(unescape(configs.setModifyData));
          }
          if (saveData.length > 0)
            str = JSON.stringify(saveData);
        }
        return str;
      },
      //设置表单的校验        
      checkForm(commandType){
        var self = this;
        function getCtlVal(id){
          return self.dataMap[id].value;
        }    
        let taskInfor = this.row;
        let configs = JSON.parse(taskInfor.DATACONFIGS);
        let nodeId = taskInfor.NODEID;//流程当前步奏
        let flowConfig = configs.flowConfig;
        let formData = this.formData;
        let msg = "";       
        if(this.isEmptyObject(flowConfig)){
            return true;
        }
        if(typeof(flowConfig[nodeId])!="undefined"){
          for(let i=0;i<flowConfig[nodeId].items.length;i++){
            let validateItem=flowConfig[nodeId].items[i];
            if(validateItem.validate){
              let val=getCtlVal(validateItem.Id);
              if(val==""&&validateItem.commandType.indexOf(commandType)!=-1){
                msg=validateItem.errMsg;
                break;
              }  
            }             
          }
        }
        //执行自定义代码            
        if(typeof(configs.checkForm)!="undefined"&&configs.checkForm!=""){
          eval(unescape(configs.checkForm))
        }
        if(msg=="")
          return true;
        else{
          this.$vux.toast.text(msg, 'middle')
          return false;
        }
      },
      entrust() {
        // 选人过来的员工号（也是“新执行人：的员工号）
        let userID = this.$refs.executeLeader.getValues('user_no');
        // 原执行人的员工号也是登陆人的员工号
        let user = this.user.USER_NO;
        if (userID == "") {
            // 显示文字
          this.$vux.toast.text('请选择新执行人', 'middle')
          return false;
        }
        if (user == userID) {
          this.$vux.toast.text('不能委托给自己！', 'middle')
          return;
        }

        if (!this.reason) {
          this.$vux.toast.text('请输入委托原因', 'middle')
          return false;
        }
        this.doTrust();
      },
      //委托
      doTrust() {

        let taskInfor = this.row;
        let configs = JSON.parse(taskInfor.dataconfigs);

        let consignMemo = this.reason; // 输入的委托原因
        let workItemId = taskInfor.WrkID;
        let keyid = taskInfor.KeyID;
        let defKey = taskInfor.defKey;
        let flowID = taskInfor.FlowID;
        let nodeId = taskInfor.nodeId;
        let defId = taskInfor.defId;
        let linkname = taskInfor.linkname;
        let mobileFlowID = taskInfor.MobileFlowID;
        let taskExecutorName =this.user.userName; //原执行人姓名
        let taskExecutor = taskInfor.taskExecutor; // 登录者的英文名


        let sys = configs.belongSys.toUpperCase() + '_URL'


        //委托人
        let AuditUserFullName2 = "";
        let AuditUserName2 = "";

        AuditUserFullName2 = this.$refs.executeLeader.getValues('User_FullName')
        AuditUserName2 =  this.$refs.executeLeader.getValues('user_name')

        let vText = '{' +
          '"_method":"formflow.doConsignFlow",' +
          '"_param":{' +
          '"flowParam":{' +
          '"defKey":"' + defKey + '",' +
          '"taskId":"' + workItemId + '",' +
          '"instId":"' + flowID + '",' +
          '"userCommandId":"transfer",' // 默认的
          +
          '"userCommandType":"transfer",' // 默认的
          +
          '"isAdmin":true,' // 默认的
          +
          '"taskComment":"委托原因：' + consignMemo + '<br/>原执行人：' + taskExecutorName + '",' // 委托原因+原执行人姓名
          +
          '"businessKey":"' + keyid + '",' +
          '"userName":"' + taskExecutor + '",' // 登录者的英文名
          +
          '"description":"111",' +
          '"extParam":{' +
          '"transferUserId":"' + AuditUserName2 + '"' // 选人的id
          +
          '}' +
          '}' +
          '}' +
          '}';
          this.$vux.loading.show({
            text: '正在提交'
            })
        this.$http({
          method: 'post',
          url: this.getReqUrl(this[sys]),
          data: {
            FixJSON: vText
          }
        }).then((res) => {
            this.$vux.loading.hide()
            if(this.isEmptyObject(res.data)){
              this.$vux.toast.text('提交成功', 'middle')
              setTimeout(()=>{
                this.$vux.toast.hide()
                this.$router.push('/task?refresh=true')
              },1000)
            }
        })

        // appcan.request.ajax({
        //   url: url,
        //   type: 'GET',
        //   data: {
        //     url: vURL,
        //     text: vText
        //   },
        //   dataType: "text",
        //   success: function (data1) {
        //     appcan.window.closeToast();
        //     let vjson = JSON.parse(data1);
        //     if (vjson.status == 0) {
        //       appcan.window.openToast('提交成功', 2000);
        //       appcan.window.evaluatePopoverScript('taskList', 'content', 'getdata(1)');
        //       appcan.window.evaluateScript('index', 'getTaskCount(1);');
        //       appcan.window.evaluateScript("TM-Task", "appcan.window.close(-1)");
        //     } else {
        //       appcan.window.openToast('提交失败', 2000);
        //     }
        //   }
        // });
      },
      checkName(val){
        if(val){
          return val.replace(/<[^>]+>/g,'')
        }
      },
      formatDateTime(val) {
        return val.substring(0, 10);
      },
      radio(data) {
        if (!data)
          return false
        let list = []
        list = data.map(item => {
          if (item.value)
            return {
              key: item.value.replace(/(^\s*)|(\s*$)/g, ""),
              value: item.text.replace(/(^\s*)|(\s*$)/g, "")
            }
        })
        return list
      },
      goBack() {
        this.$router.go(-1);
      }
    },
    computed:{
      user() {
        return this.$store.state.user;
      },
      row() {//页面中使用row来指代当前记录
        return this.$store.state.currentRow;
      },
      flowConfig() {
        let map = {};
        let config = JSON.parse(this.row.DATACONFIGS);
        if(config.flowConfig && config.flowConfig[this.row.NODEID]){
          let arr = config.flowConfig[this.row.NODEID].items;
          arr.forEach(function (item) {
              map[item.Id] = item;
            });
        }
        return map;
      },
      dataMap() {
         let map = {};
        if(this.list){
          this.list.forEach(function (item) {
            map[item.Id] = item;
          });
          }
        return map
      },
      configs() {
        return JSON.parse(this.row.DATACONFIGS);
      },
      height(){
        return this.row.STATE == '待验收' ? '100%' : 'calc(100% - 42px)'
      }
    }, 
    components: {
      Timeline,
      TimelineItem,
      TimelineTitle,
    }
  }
</script>

<style>
  .black {
    color: #343434;
  }
  .approveBtn {
    position: fixed;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
    min-height: 2.4rem;
    font-size: 0.8rem
  }
  .btn-area {
    position: fixed;
    bottom: 0;
    width: 100%;
    margin-bottom: 16px;
  }
  .btn {
    float: left;
    font-size: 14px;
    height: 45px;
    line-height: 45px;
    width: 139px;
    text-align: center;
    margin: 8px;
  }
  .general-btn {
    font-size: 14px;
    color: #FEFEFE;
    background-color: #4852D0;
    border-radius:2px;
  }
  .back-btn {
    font-size: 14px;
    color: #4852D0;
    background-color: #F2F4F6;
    border-radius:2px;
  }
  .my-cell{
    padding: 0 40px !important;
  }
  .entrust-btn {
    text-align: center;
    font-size: 14px;
    color: #FEFEFE;
    background-color: #4852D0;
    border-radius: 2px;
    height: 45px;
    line-height: 45px;
    margin: 0 41px;
  }
</style>
